<%@ page import="database.ClassDb" %>
<%@ page import="database.User" %>
<%@ page import="java.util.List" %>
<%@ page import="utils.StringUtils" %><%--
  Created by IntelliJ IDEA.
  User: jimmyhsu
  Date: 2016/12/12
  Time: 20:41
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" href="../../static/style/weui.css"/>
    <link rel="stylesheet" href="../../static/example/example.css"/>
    <link rel="stylesheet" href="../../static/style/myStyle.css"/>
    <%
        List<User> usersNotInClass = ClassDb.selectStudentsNotInClass();
        String classIdStr = request.getParameter("classId");
        int classId = -1;
        if (!StringUtils.isEmpty(classIdStr)) {
            classId = Integer.parseInt(classIdStr);
        }
        String refresh = request.getParameter("refresh");
        if (!StringUtils.isEmpty(refresh) && refresh.equals("true")) {
            response.getWriter().print("<script>window.parent.right_frame.location.href='importClassRight.jsp?classId="+classId+"';</script>");
        }
    %>
</head>
<body style="background-color: transparent; color: #ffffff;">

<center>
    <h3>向班级导入学生</h3>
    <p>按学号导入(多个用逗号隔开)</p>
    <form action='addSeveralUsersToClass' method='get' onsubmit="return check()">
        <input type='hidden' name='classId' value='<%=classId%>'>
        <textarea id="input1" cols="30" rows="1" name = "inputIds"></textarea>
        <input class="weui_btn weui_btn_mini weui_btn_default" style = "position: relative" type='submit' value='添加'/>
    </form>
    <br>
    以下为没有班级的同学：<br>
    <%
	for (User user : usersNotInClass) {
			%>
    <a href="javascript:void(0);" onclick="appendStudent('<%=user.getId()%>')"><%=user.getId()%>&nbsp;<%=user.getName()%></a><br>
    <%
	}
%>
    <br>
</center>
<script src="../../static/js/jquery-1.10.2.js"></script>
</body>
<script type="text/javascript">
    var classId = document.getElementsByName("classId")[0];
    function check() {
        if (classId.value > 0) {
            return true;
        } else {
            alert('请先在上方选择一个班级');
            return false;
        }
    }
    function appendStudent(val) {
        if ($('#input1').html()=='') {
            $('#input1').html(val);
        } else if ($('#input1').html().indexOf(val)>=0) {
        } else {
            $('#input1').html($('#input1').html() + ',' + val);
        }
    }
</script>
</html>
